import DictTag, { DictValueEnum } from "@/components/DictTag";
import { createIcon } from "@/utils/IconUtil";
import { ProColumns } from "@ant-design/pro-table";
import { Avatar, Divider, Dropdown, MenuProps, Popconfirm, Space, Switch, Typography } from "antd";

// 定义所有列的工厂函数
export const createTableColumns = (
	statusOptions: DictValueEnum,
	handleColumnEditor: (record: API.Setting.RoleVo) => void,
	handleColumnRemove: (record: API.Setting.RoleVo) => void,
	handleColumnAuth: (record: API.Setting.RoleVo) => void,
	handleColumnMenu: (record: API.Setting.RoleVo) => void,
	handlePremission: (record: API.Setting.RoleVo) => void
): ProColumns<API.Setting.RoleVo>[] => {
	return [
		{
			title: "角色名称",
			dataIndex: "roleName",
			valueType: "text"
		},
		{
			title: "角色编码",
			dataIndex: "roleKey",
			valueType: "text"
		},
		{
			title: "显示顺序",
			dataIndex: "sort",
			valueType: "text",
			hideInSearch: true,
			sorter: (a, b) => a.sort - b.sort
		},
		{
			title: "角色状态",
			dataIndex: "status",
			valueType: "select",
			filters: true,
			onFilter: true,
			valueEnum: statusOptions,
			render: (_, record) => {
				return <DictTag type="badge" enums={statusOptions} value={record.status} />;
			}
		},
		// {
		// 	title: "状态",
		// 	dataIndex: "status",
		// 	valueType: "select",
		// 	valueEnum: statusOptions,
		// 	render: (_, record) => {
		// 		return <DictTag enums={statusOptions} type="tag" value={record.status} />;
		// 	}
		// },
		{
			title: "操作",
			dataIndex: "option",
			width: "250px",
			valueType: "option",
			fixed: "right",
			render: (_, record: any) => {
				return (
					<>
						{!record.superAdmin && (
							<Space size={1} split={<Divider type="vertical" />}>
								<Typography.Link
									key="editor"
									onClick={() => {
										handleColumnEditor(record);
									}}
								>
									编辑
								</Typography.Link>
								{/* <Typography.Link
									key="auth"
									onClick={() => {
										handleColumnAuth(record);
									}}
								>
									授权
								</Typography.Link> */}
								<Typography.Link
									key="menu"
									onClick={() => {
										handleColumnMenu(record);
									}}
								>
									菜单
								</Typography.Link>
								<Typography.Link
									key="permission"
									onClick={() => {
										handlePremission(record);
									}}
								>
									权限
								</Typography.Link>
								<Popconfirm
									placement="bottomRight"
									title="提示"
									description={`确认要删除角色名称为: "${record.roleName}" 的角色吗？`}
									key="edit"
									onConfirm={async () => handleColumnRemove(record)}
									okText="确认"
									cancelText="取消"
								>
									<Typography.Link type="danger" key="remove">
										删除
									</Typography.Link>
								</Popconfirm>
							</Space>
						)}
					</>
				);
			}
		}
	];
};
export const proTableCardProps = {
	bodyStyle: {
		paddingInline: 0,
		paddingBlock: 0
	}
};

export const pagination = {
	showQuickJumper: true,
	showSizeChanger: true
};

export const formTitle = ["新增角色", "编辑角色"];
